from qttab.pd import get_df_from_db, get_cols_values_dict


def get_doc_info_from_doc_code(doc_code: str):
    df = get_df_from_db("doc", f"file_name like '%{doc_code}%'")
    if df.empty:
        return
    col_list = ["id", "once_id", "file_name", "title", "reviewed_result"]
    return get_cols_values_dict(df, col_list)


def make_doc_name(doc_info_dict:dict) ->str:
    if doc_info_dict:
        file_name = doc_info_dict["file_name"][0]
        reviewed_result = doc_info_dict["reviewed_result"][0]
        if reviewed_result:
            file_name = file_name + "-" + reviewed_result
        title = doc_info_dict["title"][0]
        return file_name + title
    else:
        return ""
